/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package csvreader.controller;

import csvreader.model.Contact;
import csvreader.view.AddPanel;
import csvreader.view.MainFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author habib <imamhabibpamungkas@gmail.com>
 */
public class AddController {
    private AddPanel add;
    private MainFrame frame;
    private ResetText rs;

    public AddController(AddPanel add, MainFrame frame) {
        this.add = add;
        this.frame = frame;
        rs = new ResetText();
    }
       
    public void submit(){
        try {
            String nama = add.getTextFieldNama().getText();
            String telepon1 = add.getTextFieldTelepon1().getText();
            String telepon2 = add.getTextFieldTelepon2().getText();
            String telepon3 = add.getTextFieldTelepon3().getText();
            String email = add.getTextFieldEmail().getText();
            String keterangan = add.getTextFieldKeterangan().getText();
            if (keterangan.equals("")) {
                keterangan = " ";
            }
            frame.getDaoMhs().addData(new Contact(nama, telepon1, telepon2, telepon3, email, keterangan));
            ResetText.resetJTextField(add);
            frame.loadData();
            add.setVisible(false);
        } catch (Exception ex) {
            JOptionPane.showMessageDialog(frame, ex.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
            ResetText.resetJTextField(add);
        }
    }
}
